<template>
	<view class="info">
		<view class="header">
			<view class="title">
				工单信息
				<Tag :status="state" />
			</view>
		</view>
		<view class="body">
			<!-- 上半部分：基本信息 -->
			<view class="form-section">
				<view class="form-item">
					<view class="label">
						工单号：
					</view>
					<view class="text">
						{{ data.workCode || '--' }}
					</view>
				</view>
				<view class="form-item">
					<view class="label">
						产品编码：
					</view>
					<view class="text">
						{{ data.materialCode || '--' }}
					</view>
				</view>
				<view class="form-item">
					<view class="label">
						产品名称：
					</view>
					<view class="text">
						{{ data.materialName || '--' }}
					</view>
				</view>
				<view class="form-item">
					<view class="label">
						图号规格：
					</view>
					<view class="text">
						{{ data.customMaterialCode || '--' }}
					</view>
				</view>
				<view class="form-item">
					<view class="label">
						材料牌号：
					</view>
					<view class="text">
						{{ data.materialMark || '--' }}
					</view>
				</view>
				<view class="form-item">
					<view class="label">
						计划数量：
					</view>
					<view class="text">
						{{ data.planProduceQuantity || '--' }}
					</view>
				</view>
				<view class="form-item">
					<view class="label">
						工单状态：
					</view>
					<view class="text">
						{{ state || '--' }}
					</view>
				</view>
			</view>
			
			<!-- 分割线 -->
			<view class="divider"></view>
			
			<!-- 下半部分：生产数据 -->
			<view class="form-section">
				<view class="form-item">
					<view class="label">
						报工合格总数：
					</view>
					<view class="text">
						{{ dataNumber.passCount||'--' }}
					</view>
				</view>
				<view class="form-item">
					<view class="label">
						不良总数：
					</view>
					<view class="text">
						{{ dataNumber.failCount|| '--' }}
					</view>
				</view>
				<view class="form-item">
					<view class="label">
						报废总数：
					</view>
					<view class="text">
						{{ dataNumber.scrapCount||'--' }}
					</view>
				</view>
				<view class="form-item">
					<view class="label">
						投料总数：
					</view>
					<view class="text" style="color:#5cb3de;text-decoration:underline" @click="openFeedingDetail">
						查看
					</view>
				</view>
<!-- 				<view class="form-item" v-if="!hideCuttingPlan && data.cuttingPlanCode">
					<view class="label">
						开料详情：
					</view>
					<view class="text" style="color:#5cb3de" @click="openCuttingPlan">
						查看开料计划单
					</view>
				</view> -->
				<view class="form-item">
					<view class="label">
						备注：
					</view>
					<view class="text">
						{{ data.remarks || '--' }}
					</view>
				</view>
			</view>
		</view>
		<view class="footer">
			<Button text @click="back">
				查看其他工单
			</Button>
			<Button type="success" @click="goto('/pages/workbench/index')" class="back_btn">
				返回主菜单
			</Button>
		</view>

		<!-- 投料详情弹框 -->
		<Modal title="投料详情汇总" ref="feedingModal" width="80%" noComfirm>
			<view class="table-demo">
				<Table ref="table" :columns="feedingColumns" :table-data="dataNumber.historyFeedingList" :pagination="false"
					:tooltip="false">
				</Table>
			</view>
		</Modal>
	</view>
</template>

<script>
	import Tag from "@/components/tag/index.vue";
	import Button from "@/components/button/index.vue";
	import Modal from '@/components/modal/index.vue';
	import Table from '@/components/table/index.vue';
	export default {
		props: {
			data: {
				type: Object,
				default: () => {
					return {
						state: '状态'
					}
				},
			},
			dataNumber: {
				type: Object,
				default: () => {
					return {
						tableData: []
					}
				},
			},
			hideCuttingPlan: {
				type: Boolean,
				default: false
			},
			backUrl: {
				type: String,
				default: ''
			},
			state: {
				type: String,
				default: ''
			},
		},
		components: {
			Tag,
			Button,
			Modal,
			Table
		},
		data() {
			return {
				feedingColumns: [{
						label: '物料编码',
						value: 'materialCode'
					},
					{
						label: '物料名称',
						value: 'materialName'
					},
					{
						label: '重量',
						value: 'weight'
					},
					{
						label: '理论重量',
						value: 'theoryWeight'
					},
					{
						label: '单位',
						value: 'unit'
					}
				]
			};
		},
		methods: {
			openCuttingPlan() {
				this.$emit('openCuttingPlan');
			},
			goto(url) {
				uni.navigateTo({
					url,
					animationType: "pop-in",
					animationDuration: 1000,
				})
			},
			back() {
				uni.navigateBack()
				// if (this.backUrl) {
				// 	this.goto(this.backUrl);
				// } else {
				// }
			},
			openFeedingDetail() {
				console.log(this.dataNumber.historyFeedingList);
				this.$refs.feedingModal.open();
			}
		}
	}
</script>

<style lang="scss">
	.info {
		flex: 1;
		display: flex;
		flex-direction: column;
		height: 100%;

		.header {
			flex: 0 auto;
			padding: 0 3rem;

			.title {
				display: flex;
				justify-content: flex-start;
				align-items: center;
				padding: 2rem 0;
				border-bottom: 1px solid #ccc;
				font-weight: bold;
			}
		}

		.body {
			flex: 1;
			display: flex;
			flex-direction: column;
			padding: 3rem 5rem 0;
			
			.form-section {
				margin-bottom: 2rem;
				
				&:last-child {
					margin-bottom: 0;
				}
			}
			
			.divider {
				height: 1px;
				background-color: #eee;
				margin: 2rem 0;
			}

			.form-item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: 0 0 2.5rem;

				.label {
					color: #999;
					flex: 1;
				}

				.text {
					color: #333;
					width: 26rem;
					word-break: break-all;
				}

				&:last-child {
					margin-bottom: 0;
				}
			}
		}

		.footer {
			flex: 0 auto;
			padding: 0 3rem 3rem;
		}

		.text_btn {
			margin-top: 3rem;
		}

		.back_btn {
			margin-top: 2rem;
		}
	}
</style>